<template>
	<view class="content">
		<view class="">
			<u-navbar leftIcon="search" :title="title" :bgColor="bgColor" placeholder
				:titleStyle="{ color: '#FFF', fontSize: '32rpx' }"></u-navbar>

			<!-- <button @getuserinfo="authUserInfo" open-type="getUserInfo">授权</button> -->
			<view class="search">
				<u-search placeholder="输入要排队商家名称" v-model="keyword" @search="search" @custom="search"></u-search>
			</view>
			<view class="swiper">
				<u-swiper :list="list1" @click="click" height="200"></u-swiper>
			</view>
		</view>
		<!-- 首页{{userName}}
		{{getUserInfo.nickname}} -->
	</view>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {
				title: '首页',
				bgColor: '#EA5455',
				userName: this.$store.state.userinfo.nickname, //小程序需要这样读取
				keyword: '',
				list1: [
					'https://cdn.uviewui.com/uview/swiper/swiper1.png',
					'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					'https://cdn.uviewui.com/uview/swiper/swiper3.png',
				]
			}
		},
		onLoad() {
			// this.login()
			console.log(this.getIsLogin)
			if (!this.getIsLogin) {
				this.init()
			}
			console.log(this.$store)
		},
		computed: {
			...mapGetters(['getUserInfo', 'getNeedAuth', 'getIsLogin'])

		},
		methods: {
			...mapActions(['login', 'authUserInfo']),
			init() {
				this.login()
			},
			search() {
				console.log(this.keyword)
				//跳转到tabBar只能用switchTab
				uni.switchTab({
					url: '/pages/hot/hot?pa=' + this.keyword,
					fail(err) {
						console.log(err)
					}
				})
			}
			// login() {
			// 	uni.login({
			// 		provider: 'weixin',
			// 		success: (res) => {
			// 			console.log('获取code', res)
			// 			this.$u.api.login({
			// 				data: {
			// 					code: res.code,
			// 					token: uni.getStorageSync('token')
			// 				}
			// 			}).then((res) => {
			// 				console.log(res)
			// 				uni.setStorageSync('token', res.data.token)
			// 			})
			// 		}
			// 	})
			// },
			// authUserInfo() {
			// 	uni.getUserInfo({
			// 		// des: '1111',
			// 		provider: 'weixin',
			// 		lang: 'zh_CN',
			// 		success: res => {
			// 			console.log("用户", JSON.stringify(res))
			// 			this.userinfo = {
			// 				nickname: res.userInfo.nickName,
			// 				sex: res.userInfo.gender === 1,
			// 				avatar: res.userInfo.avatarUrl,
			// 				city: res.userInfo.city
			// 			}
			// 			this.$u.api.auth(this.userinfo).then(res => {
			// 				console.log('res', res)
			// 			})
			// 		}
			// 	})
			// }
		}
	}
</script>

<style scoped lang="scss">
	.content {
		.search {
			margin: 10rpx 20rpx;
		}

		.swiper {}
	}
</style>
